import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import router from './router'
import store from "./store";
import echarts from 'echarts'
import {getRequest} from './utils/api'
import {postRequest} from './utils/api'
import {deleteRequest} from './utils/api'
import {putRequest} from './utils/api'
import {postKeyValueRequest} from "./utils/api";
import {initMenu} from "./utils/menus";
import 'font-awesome/css/font-awesome.min.css'
import '../photo/theme/index.css'

Vue.prototype.$echarts = echarts
Vue.prototype.getRequest = getRequest;
Vue.prototype.postRequest = postRequest;
Vue.prototype.deleteRequest = deleteRequest;
Vue.prototype.putRequest = putRequest;
Vue.prototype.postKeyValueRequest = postKeyValueRequest;

Vue.config.productionTip = false;

Vue.use(ElementUI);

/**
 * router钩子，每次请求路由前做校验
 *
 */
router.beforeEach((to, from, next)=> {
    //如果访问首页，通行
    if(to.path=='/'||to.path=='/test'){
      next();
    }else {
        //如果用户登陆则直接显示菜单
        if(window.sessionStorage.getItem("user")){
            initMenu(router,store);
            next();
        }else{//如果用户没有登陆却直接访问了登陆后的路径则先跳回到首页
            //重定向到用户想直接到达的页面
            next('/?redirect='+to.path);
        }
    }
})
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
